﻿
using KinectWindowLib;
using KinectWindowLib.Graphics;
using KinectWindowLib.NuiControls;
using KinectWindowLib.WIndows;
using KinectWindows.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using KinectWindowLib.Windows;

namespace KinectWindows.Windows
{
    public delegate void OnPaint(NuiWindow display);
    // Repesent all Windows and controls that are drived from VtkProp
    public class NuiWindow
    {

        #region Delegates
        public OnPaint onPaint;        
        #endregion
        public List<NuiWidget> Children { set; get; }      
        public NuiWindow()
        {
            // TODO: Complete member initialization
            Children = new List<NuiWidget>();
        }
        public void SetBoarderWidth(int width)
        {
            WindowAttributes.SetBoarderwidth(width);
        }
        public void SetSize(Vector2 Scale)
        {
            WindowAttributes.SetSize(Scale.X, Scale.Y);
        }
        public NuiWindow getParent()
        {
            return WindowAttributes.Parent;
        }

        // Paint the Control on The VTK Stage
        public virtual void OnDraw(NuiCanvas display)
        {
            if (Children.Count > 0)
            {
                for (int i = 0; i < Children.Count; i++)
                    Children[i].OnDraw(display);
            }
          // this.on
        }
        // Paint the Control
        internal void Paint()
        {
            DrawWindow();

            if (Children.Count > 0)
            {
                for (int i = 0; i < Children.Count; i++)
                    Children[i].Paint();
            }

            onPaint(this);
        }

        // Add a new Window to the screen
        public void Add(NuiWidget wind)
        {
            Children.Add(wind);
        }

        #region window Propraties
        public float Left { get { return WindowAttributes.x; } }
        public float Top {  get { return WindowAttributes.y; } }
        public float Width { get { return WindowAttributes.width; }   }
        public float Height { get { return WindowAttributes.height; }  }
        public String Name {  get { return WindowAttributes.Name; } }
        public long Id { get { return WindowAttributes.Id; } }
        public Object Tag { get { return WindowAttributes.Tag; } }
        
        #endregion
        #region for internal use
        // Draw the window
        protected void DrawWindow()
        {
            DrawBackground();
            DrawBoarders();
           
        }
        // Draw the Window Background
        private void DrawBackground()
        {
           
        }

        // Draw the Window Boarder
        private void DrawBoarders()
        {
        }
        
        #endregion


        internal WindowAttribute WindowAttributes { get; set; }

        public GraphicContext GCContext { get; set; }

        public void SetId(int p)
        {
            WindowAttributes.setId((long)p);
        }
        public void SetLocation(Vector2 vec)
        {
            WindowAttributes.SetLocation(vec.X, vec.Y);
        }


        public Vector2 Location { get { return new Vector2(WindowAttributes.x, WindowAttributes.y); } }

        internal void SetCurser(SharpGLWinformsApplication1.NuiCursor curser)
        {
            throw new NotImplementedException();
        }




        public int ZOrder { get; set; }

        internal void SetFocus()
        {
            throw new NotImplementedException();
        }

        internal void LostFocus()
        {
            throw new NotImplementedException();
        }
    }
    [Flags]
    public enum WindowClass
    {
        WC_IDLE, // IDLE WINDOW IS A WINDOW WITH A TITLEBAR CLOSE BUTTON AND DO NOT INTERACT WITH NUI SIGNALS
        WC_SIMPLE_WINDOW,
        WC_DIALOG_BOX,
        WC_ROOT
    }
}
